// 题意：求树上三个点相连的最小距离
//
// 题解：lca，转rmq在线做，用dfs得到欧拉序列对应的深度序列求最小值，
//       当然还要维护min_index表示下标为i的元素在欧拉序列中第一个出现
//       的位置。
//       答案的话就是:
//       	cost_to_root[a] + cost_to_root[b] + cost_to_root[c]
//       		- cost_to_root[lca(a, b)] - cost_to_root[lca(a, c)]
//       			- cost_to_root[lca(b, c)]
//       证明可以yy一下。
//       用了st求rmq，所以复杂度是O(n*log(n) + q),
//       对于相邻元素差 正负一 的rmq有复杂度为 O(n) 的做法，回头再研究。
//
// run: $exec < input > output
#include <iostream>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>

#define NDEBUG

int const maxn = 50007;
int cost_to_root[maxn];
bool vis[maxn];
int n, q;

typedef std::pair<int, int> node_type;
typedef std::vector<node_type> adj_edge;
typedef adj_edge::iterator edge_iter;
std::vector<adj_edge> graph;
std::vector<int> euler_tour;
std::vector<int> depth;
std::vector<int> min_index;

template <
	class T,
	class COMPARE = std::less<T>
>
struct sparse_table
{
	typedef T value_type;
	typedef unsigned int size_type;
	typedef COMPARE comparer;
	typedef std::vector<value_type> vector_type;

	inline size_type log2(size_type len) const
	{
		size_type tmp = 0;
		for (; size_type(1 << tmp) <= len; tmp++); // FIXME 11 neednot write size_type
		return tmp - 1;
	}

	sparse_table(comparer cmp = comparer()) : cmp(cmp) {}

	void init(vector_type const & data)
	{
		size_type n = data.size();
		size_type len = log2(n);

		for (size_type i = 0; i < n; i++) st[i][0] = i;
		for (size_type l = 1; l <= len; l++)
			for (size_type i = 0; (i + (1<<l) - 1) < n; i++)
				if (cmp(data[ st[i][l - 1] ], data[ st[i + (1<<(l-1))][l - 1] ]))
					st[i][l] = st[i][l - 1];
				else
					st[i][l] = st[i + (1 << (l-1))][l - 1];
	}

	// [l, r]
	size_type query_interval_index(vector_type const & data, size_type l, size_type r) const
	{
		int k = log2(r - l + 1);
		if (cmp(data[ st[l][k] ], data[ st[r - (1<<k) + 1][k] ]))
			return st[l][k];
		else
			return st[r - (1<<k) + 1][k];
	}

	// [l, r]
	value_type query_interval(vector_type const & data, size_type l, size_type r) const
	{
		return data[ query_interval_index(data, l, r) ];
	}

private:
	size_type static const maxn = 100007;
	size_type static const  len = 17;
	size_type st[maxn][len];
	comparer cmp;
};


void dfs(int u, int dep)
{
	vis[u] = true;
	euler_tour.push_back(u);
	depth.push_back(dep);
	min_index.push_back(euler_tour.size() - 1);
	min_index[u] = euler_tour.size() - 1;

	for (edge_iter it = graph[u].begin(); it != graph[u].end(); ++it) {
		int v = (*it).first, c = (*it).second;
		if (vis[v]) continue;
		cost_to_root[v] = cost_to_root[u] + c;
		dfs(v, dep + 1);
		euler_tour.push_back(u);
		depth.push_back(dep);
	}
}

void init_rmq(sparse_table<int> & st)
{
	cost_to_root[0] = 0;
	dfs(0, 0);
	st.init(depth);

#ifndef NDEBUG
	std::cout << "euler tour && depth:\n";
	for (auto i : euler_tour) std::cout << i << ' '; std::cout << '\n';
	for (auto i : depth) std::cout << i << ' '; std::cout << '\n';
	std::cout << "min_index:\n";
	for (auto i : min_index) std::cout << i << ' '; std::cout << '\n';
#endif
}

int lca(sparse_table<int> const & st, int a, int b)
{
	if (min_index[a] > min_index[b]) std::swap(a, b);
	return euler_tour[st.query_interval_index(depth, min_index[a], min_index[b])];
}

int query(sparse_table<int> const & st, int a, int b, int c)
{
	int lab = lca(st, a, b);
	int lac = lca(st, a, c);
	int lbc = lca(st, b, c);

#ifndef NDEBUG
	std::cout << "a = " << a << " b = " << b << " c = " << c << '\n';
	std::cout << "lca(a, b) = " << lab << '\n';
	std::cout << "lca(a, c) = " << lac << '\n';
	std::cout << "lca(b, c) = " << lbc << '\n';
#endif
	return cost_to_root[a] + cost_to_root[b] + cost_to_root[c]
			- cost_to_root[lab] - cost_to_root[lbc] - cost_to_root[lac];
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	for (bool flag = false; std::cin >> n; flag = true) {
		if (flag) std::cout << '\n';
		graph.clear(); graph.resize(n);
		min_index.clear(); min_index.resize(n);
		euler_tour.clear();
		depth.clear();
		std::fill(vis, vis + n, false);
		for (int i = 0, x, y; i < n-1; i++) {
			node_type tmp;
			std::cin >> x >> y >> tmp.second;
			tmp.first = y; graph[x].push_back(tmp);
			tmp.first = x; graph[y].push_back(tmp);
		}

		sparse_table<int> st;
		init_rmq(st);

		std::cin >> q;
		for (int i = 0, a, b, c; i < q; i++) {
			std::cin >> a >> b >> c;
			std::cout << query(st, a, b, c) << '\n';
		}
	}
}

